﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoolCode.Data;
using CoolCode.Services;
using CoolCode.Models;
using CoolCode.Bracket.LinqToEntity.Entities;

namespace CoolCode.Bracket.LinqToEntity.Services
{
    public class TrackService : BracketService, ITrackService //ServiceBase, ITrackService
    {
        #region Data Access Object

        private IRepository<Log> _logger = null;
        public IRepository<Log> Logger
        {
            get
            {
                if (_logger == null)
                    _logger = this.CreateRepository<Log>();
                return _logger;
            }
            set
            {
                _logger = value;
            }
        }

        #endregion

        public TrackService():base()
        {
        }

        /// <summary>
        /// save program log and submit transation
        /// </summary>
        /// <param name="entity"></param>
        public virtual void LogAndSubmit(ILog log)
        {
            if (this.Log && log != null)
            {
                Log entity = new Log
                {
                    From = log.From,
                    Desc = log.Desc,
                    Name = log.Name,
                    Path = log.Path,
                    Time = log.Time,
                    Type = log.Type,
                    User = log.User
                };
                Logger.Insert(entity);
            }
            this.Submit();
        }
    }
}
